home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 1997 July / PC Pro July 1997.iso / extras / code / visprog32.txt < prev   
Encoding:
Text File  |  1997-04-28  |  5.6 KB  |  207 lines

  1.  
  2. Listing One
  3.  
  4. procedure TExplorerButton.WMRButtonDown (var Message: TWMRButtonDown);
  5. begin
  6.     { Disable AutoPopup before calling Inherited }
  7.     if PopupMenu <> Nil then PopupMenu.AutoPopup := False;
  8.     Inherited;
  9. end;
  10.  
  11. procedure TExplorerButton.WMLButtonDown (var Message: TWMLButtonDown);
  12. var
  13.     pt: TPoint;
  14.     InControl: Boolean;
  15. begin
  16.     Inherited;
  17.     InControl := PtInRect (GetClientRect, Point (Message.XPos, Message.YPos));
  18.  
  19.     if InControl then
  20.     begin
  21.         MouseCapture := True;
  22.         fState := bsDown;
  23.         Invalidate;
  24.  
  25.         if PopupMenu <> Nil then
  26.         begin
  27.             pt := Parent.ClientToScreen (Point (Left - 1, Top + Height));
  28.             PopupMenu.Alignment := paLeft;
  29.             PopupMenu.PopupComponent := Self;
  30.             PopupMenu.Popup (pt.x, pt.y);
  31.             fState := bsInactive;
  32.             MouseCapture := False;
  33.             Invalidate;
  34.         end;
  35.     end;
  36. end;
  37.  
  38. Listing Two 
  39.  
  40. procedure TExplorerButton.Paint;
  41. var
  42.     x, y: Integer;
  43.     Glyph: TBitmap;
  44.     txtRect, bitRect, glyphRect: TRect;
  45.  
  46.     procedure DrawMenuGlyph (x, y: Integer; Color: TColor; Style: TBrushStyle);
  47.     begin
  48.         with Canvas do
  49.         begin
  50.             Pen.Color := Color;
  51.             Brush.Color := clBlack;
  52.             Brush.Style := Style;
  53.             Canvas.Polygon([Point (x, y), Point (x + 8, y), Point (x + 4, y + 4)]);
  54.         end;
  55.     end;
  56.  
  57. begin
  58.     with Canvas do
  59.     begin
  60.         ╔<<< drawing code as shown last month>>>╔
  61.  
  62.         { Draw the drop-down menu 'glyph' }
  63.         if PopupMenu <> Nil then
  64.         begin
  65.             x := Width - 14; y := 4;
  66.             if Enabled then
  67.             begin
  68.                 if fState = bsDown then begin Inc (x); Inc (y); end;
  69.                 DrawMenuGlyph (x, y, clBlack, bsSolid);
  70.             end
  71.             else
  72.             begin
  73.                 DrawMenuGlyph (x, y, clBtnShadow, bsClear);
  74.                 DrawMenuGlyph (x + 1, y + 1, clBtnHighlight, bsClear);
  75.             end;
  76.         end;
  77.  
  78.         { Finally, draw the glyph }
  79.         Brush.Color := Color;
  80.         BrushCopy (bitRect, Glyph, glyphRect, fTransparentColor);
  81.     end;
  82. end;
  83.  
  84. Listing Three 
  85.  
  86. unit CoolBar;
  87.  
  88. interface
  89.  
  90. uses Messages, Windows, Classes, Controls, Forms, SysUtils, CommCtrl;
  91.  
  92. function AddCoolBar (Wnd: hWnd): hWnd;
  93. procedure AlignCoolBar (CoolBarWnd: hWnd);
  94. procedure AddBand (CoolBarWnd: hWnd; Comp: TWinControl);
  95.  
  96. implementation
  97.  
  98. const
  99.     ICC_Cool_Classes        =     $00000400;
  100.     RBS_VarHeight        =     $00000200;
  101.     RBS_BandBorder        =     $00000400;
  102.     RBBS_ChildEdge        =     $00000004;
  103.     RBBS_FixedBmp        =     $00000020;
  104.     RBBIM_Style            =     $00000001;
  105.     RBBIM_Colors        =     $00000002;
  106.     RBBIM_Child            =     $00000010;
  107.     RBBIM_ChildSize        =     $00000020;
  108.     RB_InsertBand        =     wm_User +1;
  109.  
  110.     ReBarClassName              =     'ReBarWindow32';
  111.  
  112. type
  113.     TICCEx = record
  114.                  dwSize: DWord;
  115.                  dwFlags: DWord;
  116.              end;
  117.  
  118.     TRebarInfo = record
  119.                      cbSize: UInt;
  120.                      fMask: UInt;
  121.                      fStyle: UInt;
  122.                      himl: HImageList;
  123.                      hbmBack: HBitmap;
  124.                  end;
  125.  
  126.     TRebarBandInfo = record
  127.                          cbSize: UInt;
  128.                          fMask: UInt;
  129.                          fStyle: UInt;
  130.                          clrFore: TColorRef;
  131.                          clrBack: TColorRef;
  132.                          lpText: PChar;
  133.                          cch: UInt;
  134.                          iImage: Integer;
  135.                          hWndChild: hWnd;
  136.                          cxMinChild: UInt;
  137.                          cyMinChild: UInt;
  138.                          cx: UInt;
  139.                          hbmBack: hBitmap;
  140.                          wID: UInt;
  141.                      end;
  142.  
  143. function InitCommonControlsEx (var ICCRec: TICCEx): Boolean; stdcall; external 'COMCTL32.DLL';
  144.  
  145. procedure CoolBarInit;
  146. var
  147.     ICCRec: TICCEx;
  148. begin
  149.     ICCRec.dwSize := sizeof (ICCRec);
  150.     ICCRec.dwFlags := ICC_Cool_Classes;
  151.     InitCommonControlsEx (ICCRec);
  152. end;
  153.  
  154. procedure AlignCoolBar (CoolBarWnd: hWnd);
  155. var
  156.     rcForm: TRect;
  157. begin
  158.     GetClientRect (GetParent (CoolBarWnd), rcForm);
  159.     MoveWindow (CoolBarWnd, 0, 0, rcForm.right, rcForm.Bottom, True);
  160. end;
  161.  
  162. procedure AddBand (CoolBarWnd: hWnd; Comp: TWinControl);
  163. var
  164.     rc: TRect;
  165.     rbbi: TRebarBandInfo;
  166. begin
  167.     FillChar (rbbi, sizeof (rbbi), 0);
  168.     GetWindowRect (Comp.Handle, rc);
  169.  
  170.     with rbbi do
  171.     begin
  172.         cbSize := sizeof (rbbi);
  173.         fMask := RBBIM_Child or RBBIM_ChildSize or RBBIM_Style or RBBIM_Colors;
  174.         cxMinChild := 50; { Maybe pass this as a parameter? }
  175.         cyMinChild := rc.bottom - rc.top;
  176.         clrFore := GetSysColor (Color_BtnText);
  177.         clrBack := GetSysColor (Color_BtnFace);
  178.         fStyle := RBBS_ChildEdge or RBBS_FixedBmp;
  179.         hwndChild := Comp.Handle;
  180.         iImage := 0;
  181.     end;
  182.  
  183.     SendMessage (CoolBarWnd, RB_InsertBand, -1, LongInt (@rbbi));
  184.     AlignCoolBar (CoolBarWnd);
  185. end;
  186.  
  187. function AddCoolBar (Wnd: hWnd): hWnd;
  188. var
  189.     style: DWord;
  190. begin
  191.     style := ws_Visible or ws_Child or ws_Border or ws_ClipChildren or ws_ClipSiblings;
  192.     style := style or RBS_VarHeight or rbs_BandBorder;
  193.     style := style or CCS_NoDivider or CCS_NoParentAlign;
  194.  
  195.     Result := CreateWindowEx (ws_ex_ToolWindow, ReBarClassName,
  196.                               Nil, style, 0, 0, 200, 100, Wnd,
  197.                               0, hInstance, Nil);
  198. end;
  199.  
  200. { Initialisation code for the unit }
  201.  
  202. begin
  203.     CoolBarInit;
  204. end.
  205.  
  206.  
  207.